﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.Platform.Core;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core.ServiceModel;
using Baosight.Platform.Core.UI;
using Telerik.Windows.Controls;
using Microsoft.Practices.Unity;
using Baosight.ZNH.ZMCA.UI.Controls;
using System.Windows.Data;
using Baosight.Platform.Core.UI;
using Baosight.Platform.Core.ServiceModel;
using Microsoft.Practices.Unity;
using Baosight.ZNH.ZMCA.UI.Utils;
using Baosight.ZNH.ZMCommon;

namespace Baosight.ZNH.ZMCA.UI.PopWindows
{
    /// <summary>
    /// 安全隐患详细信息
    /// </summary>
    public partial class ShowSecurityRisk : EFViewCmes 
    {
        public event EventHandler DataChanged;
        public ShowSecurityRisk()
        {
            InitializeComponent();
            //this.Loaded += new RoutedEventHandler(ZMCA47_Loaded);
        }
        public void ZMCA47LoadData()
        {
            //Combobox等页面元素的初始化，传递查询条件，显示查询结果
            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA42");
            eiInfo.Set("method", "initDataZMCA47");

            eiInfo.AddBlock(addBlock());

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, onInitDataCompleted);
        }
        public EIBlock addBlock()
        {
            EIBlock block = new EIBlock("inqu");
            EIRow row = new EIRow();
            EIColumn column = new EIColumn();
            column.SetName("fdKeyId");
            block.AddColumn(column);
            row.Add("fdKeyId", fdKeyId.Value.ToString());
            block.AddRow(row);
            return block;
        }

        //public override void Initialize(EIInfo initData)
        //{
        //    base.Initialize(initData);
        //    if (initData.Attributes.ContainsKey("fdKeyId"))
        //    {
        //        this.fdKeyId.Value = Convert.ToString(initData.Attributes["fdKeyId"]);
        //    }
        //}

        private void onInitDataCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.GetStatus() == -1)
            {
                EFWindow.Alert("数据加载失败！");
                return;
            }
            else
            {
                this.UpdateData(e.EIInfo);
                UpdateCombobox(e.EIInfo.GetBlock("result"));
                queryEFGrid();
                return;
            }
        }

        private void UpdateCombobox(EIBlock block)
        {
            if (block == null)
                return;
            EIRow row = block.GetRow(0);
            this.fdRiskSource.Value =Common.GetStringValue(row["fdSourceId"]);
            this.fdRiskClassify.Value =Common.GetStringValue(row["fdRiskClassifyId"]);
            this.fdRiskLevel.Value =Common.GetStringValue(row["fdRiskLevelId"]);
            this.fdDepartmentId.Value =Common.GetStringValue(row["fdDepartmentId"]);
            this.fdManageDepartmentId.Value = Common.GetStringValue(row["fdManageDepartmentId"]);
            this.fdWorknum.Value =Common.GetStringValue(row["fdWorknumId"]);
            this.fdWorkface.Value =Common.GetStringValue(row["fdWorkfaceId"]);
            this.fdPath.Value =Common.GetStringValue(row["fdPathId"]);

        }

        //2代表安全隐患
        public void queryEFGrid()
        {
            Dictionary<string, string> args = new Dictionary<string, string>();
            args.Add("fdKeyId", fdKeyId.Value.ToString());
            args.Add("fdProblemTypeId", "2");
            this.container.LoadView<EFCustomViewContainerPanel>("ZMCA49", args);
        }
        /// <summary>
        /// 下达指示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommandClick(object sender, RoutedEventArgs e)
        {
            EFWindow window = new EFWindow();
            window.Header = "下达工作指示";
            ZMCA45 content = new ZMCA45();
            content.SaveSuccess += new EventHandler(content_SaveSuccess);
            content.fdKeyId.Value = fdKeyId.Value.ToString();
            content.fdProblemTypeId.Value = "2";
            content.SetNew();   
            content.ZMCA45_Loaded(sender, e);
            window.Content = content;
            window.ShowDialog();
        }

        void content_SaveSuccess(object sender, EventArgs e)
        {
            if (DataChanged != null)
            {
                DataChanged(sender, e);
            }
        }
    }
}
